<html>
<head><meta charset="utf-8"><title>drop unwind soundness · wg-async-foundations · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/index.html">wg-async-foundations</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html">drop unwind soundness</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="165576700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165576700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165576700">(May 13 2019 at 22:56)</a>:</h4>
<p>Hey <span class="user-mention" data-user-id="120791">@RalfJ</span>, I have a UB question in regard to the optimization for <a href="https://github.com/rust-lang/rust/issues/52924" target="_blank" title="https://github.com/rust-lang/rust/issues/52924">#52924</a></p>



<a name="165576707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165576707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165576707">(May 13 2019 at 22:56)</a>:</h4>
<p>Not sure if you're the one to ask, but you seem most likely to know :)</p>



<a name="165576725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165576725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165576725">(May 13 2019 at 22:57)</a>:</h4>
<p>If a <code>drop</code> panics, is it safe to assume that the value is <code>StorageDead</code>?</p>



<a name="165576743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165576743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165576743">(May 13 2019 at 22:57)</a>:</h4>
<p>or could an unwind handler actually inspect the value?</p>



<a name="165576802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165576802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165576802">(May 13 2019 at 22:58)</a>:</h4>
<p>I know we certainly cannot drop the value _again_ (see <a href="https://github.com/rust-lang/rust/issues/14875" target="_blank" title="https://github.com/rust-lang/rust/issues/14875">#14875</a>)</p>



<a name="165576834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165576834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165576834">(May 13 2019 at 22:59)</a>:</h4>
<p>but that issue doesn't seem to say anything about anything else we could do with the value</p>



<a name="165582143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165582143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165582143">(May 14 2019 at 00:31)</a>:</h4>
<p><span class="user-mention" data-user-id="116883">@tmandry</span> well fwiw this works today, but MIRI complains because of the panic so I'm not sure that's enough to say anything: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=92f97259d8b64bc5cc0c3ec97076cab9" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=92f97259d8b64bc5cc0c3ec97076cab9">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=92f97259d8b64bc5cc0c3ec97076cab9</a></p>



<a name="165582602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165582602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165582602">(May 14 2019 at 00:41)</a>:</h4>
<p>hmm ok</p>



<a name="165582614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165582614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165582614">(May 14 2019 at 00:41)</a>:</h4>
<p>well I found a different way to avoid regressing the size of that one test case, so maybe it's not that important ;)</p>



<a name="165582672"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165582672" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165582672">(May 14 2019 at 00:42)</a>:</h4>
<p>but if we can assume it, it still makes some of the other futures even smaller</p>



<a name="165599134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165599134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165599134">(May 14 2019 at 07:16)</a>:</h4>
<blockquote>
<p>If a <code>drop</code> panics, is it safe to assume that the value is <code>StorageDead</code>?</p>
</blockquote>
<p><code>StorageDead</code> is for locals only, if the value was in a <code>Box</code> there's no such thing</p>



<a name="165599141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165599141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165599141">(May 14 2019 at 07:16)</a>:</h4>
<blockquote>
<p>I know we certainly cannot drop the value _again_ (see <a href="https://github.com/rust-lang/rust/issues/14875" target="_blank" title="https://github.com/rust-lang/rust/issues/14875">#14875</a>)</p>
</blockquote>
<p>you cannot drop it again in general, but specific code knowing the specific drop impl might do that</p>



<a name="165599160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165599160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165599160">(May 14 2019 at 07:17)</a>:</h4>
<p>like, I can drop an <code>i32</code> as often as I want, knowing that that is a NOP</p>



<a name="165599206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165599206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165599206">(May 14 2019 at 07:18)</a>:</h4>
<p>but in general I think there are many open questions around drop and panics, also see <a href="https://github.com/rust-lang/rust/issues/60611" target="_blank" title="https://github.com/rust-lang/rust/issues/60611">https://github.com/rust-lang/rust/issues/60611</a></p>



<a name="165599235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165599235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165599235">(May 14 2019 at 07:19)</a>:</h4>
<p>what is the optimization you have in mind?</p>



<a name="165640778"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165640778" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165640778">(May 14 2019 at 17:07)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> yes, I mean is it safe to assume the local itself is <code>StorageDead</code></p>



<a name="165640872"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165640872" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165640872">(May 14 2019 at 17:08)</a>:</h4>
<p>To ask another way: Is it UB to inspect the contents of a local, after <code>drop</code> on that local panics?</p>



<a name="165642214"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165642214" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165642214">(May 14 2019 at 17:23)</a>:</h4>
<p>I guess TL;DR is also "is my code example above UB"</p>



<a name="165642496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165642496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165642496">(May 14 2019 at 17:26)</a>:</h4>
<blockquote>
<p>To ask another way: Is it UB to inspect the contents of a local, after <code>drop</code> on that local panics?</p>
</blockquote>
<p>I don't think we can say that in general -- I am not sure through which mechanism this UB would arise.<br>
I guess you also want <em>writes</em> to that memory to be UB, so just making it uninitialized is not sufficient for your purpose?</p>



<a name="165642576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165642576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165642576">(May 14 2019 at 17:27)</a>:</h4>
<p>"killing the storage and invalidating all pointers" is what <code>StorageDead</code> is for.</p>



<a name="165642597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165642597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165642597">(May 14 2019 at 17:27)</a>:</h4>
<p>why do you want to tie this analysis to drop instead of <code>StorageDead</code>?</p>



<a name="165642834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165642834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165642834">(May 14 2019 at 17:30)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> yeah, writes would also need to be UB</p>



<a name="165642862"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165642862" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165642862">(May 14 2019 at 17:30)</a>:</h4>
<p>mainly, I want it to simplify the MIR generation</p>



<a name="165642878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165642878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165642878">(May 14 2019 at 17:30)</a>:</h4>
<p>you are exactly asking for <code>StorageDead</code> semantics then</p>



<a name="165642894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165642894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165642894">(May 14 2019 at 17:30)</a>:</h4>
<p>I wouldn't know how to make <code>drop</code> have that -- <em>in particular</em> if the drop didnt even complete</p>



<a name="165642957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165642957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165642957">(May 14 2019 at 17:31)</a>:</h4>
<p>FWIW I also need a way to mark things storagedead in code manually without moving them-- TLDR i want to make <code>drop</code> more magic ;)</p>



<a name="165642977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165642977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165642977">(May 14 2019 at 17:31)</a>:</h4>
<p>I don't like magic ;)</p>



<a name="165643038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643038">(May 14 2019 at 17:32)</a>:</h4>
<p>but I have actually brought up a non-moving version of <code>mem::forget</code> in a discussion once^^</p>



<a name="165643044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643044">(May 14 2019 at 17:32)</a>:</h4>
<p>actually, I need to change the MIR generation regardless, and I'm not 100% sure what changes I'm allowed to make...</p>



<a name="165643051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643051">(May 14 2019 at 17:32)</a>:</h4>
<p>some kind of intrinsic</p>



<a name="165643114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643114">(May 14 2019 at 17:33)</a>:</h4>
<p>in particular it isn't clear in which parts we decide not to generate <code>StorageDead</code> purely as an optimization, and which parts are due to semantics</p>



<a name="165643176"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643176" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643176">(May 14 2019 at 17:34)</a>:</h4>
<p>I'm afraid I don't know either :/ as far as I am concerned, where we insert <code>StorageDead</code> is part of our spec -- we get to make that choice, and that <em>defines</em> which code has UB. but we better document our choice well.</p>



<a name="165643280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643280">(May 14 2019 at 17:34)</a>:</h4>
<p>fair enough</p>



<a name="165643298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643298">(May 14 2019 at 17:35)</a>:</h4>
<p>having it be part of our spec that the semantics are different for generators would probably be bad XD</p>



<a name="165643326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643326">(May 14 2019 at 17:35)</a>:</h4>
<p>agreed :)</p>



<a name="165643337"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643337" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643337">(May 14 2019 at 17:35)</a>:</h4>
<p>yeah sounds like it would be nice if functions and generators would be consistent about this :D</p>



<a name="165643347"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643347" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643347">(May 14 2019 at 17:35)</a>:</h4>
<blockquote>
<p>I wouldn't know how to make <code>drop</code> have that</p>
</blockquote>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> can you elaborate on your concern here?</p>



<a name="165643441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643441">(May 14 2019 at 17:36)</a>:</h4>
<p>it's less a concern and more literally "I dont know how to define a semantics that does this". <code>drop</code> is almost a normal function call for Miri, just invoked by a dedicated MIR terminator instead of <code>Call</code>.</p>



<a name="165643479"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643479" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643479">(May 14 2019 at 17:36)</a>:</h4>
<p>there's no magic for <code>drop</code> and I quite like that :D keeps the spec simpler and easier to reason about (for compiler and unsafe code authors alike)</p>



<a name="165643561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643561">(May 14 2019 at 17:37)</a>:</h4>
<p>hmm, yes, but eliding <code>StorageDead</code> in some cases certainly makes this harder to reason about</p>



<a name="165643653"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643653" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643653">(May 14 2019 at 17:38)</a>:</h4>
<p>..let me try and remember why this matters :)</p>



<a name="165643695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643695">(May 14 2019 at 17:38)</a>:</h4>
<blockquote>
<p>I guess TL;DR is also "is my code example above UB"</p>
</blockquote>
<p>I <em>think</em> if Miri supported panics it would reject this code based on Stacked Borrows considerations -- the call to <code>drop</code> involves a mutable borrow of the local, which kills all previously created pointers.</p>



<a name="165643712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643712">(May 14 2019 at 17:39)</a>:</h4>
<p>Whether that is a happy accident or something one can derive a guarantee from, I am not sure.^^</p>



<a name="165643825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643825">(May 14 2019 at 17:40)</a>:</h4>
<p>also the mutable borrow for<code>drop</code> is a bit special, so it might or might not do what you want here</p>



<a name="165643836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643836">(May 14 2019 at 17:40)</a>:</h4>
<p>but we could reasonably define it to act like an <code>&amp;mut</code> would</p>



<a name="165643837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643837">(May 14 2019 at 17:40)</a>:</h4>
<p>That sounds like the guarantee I would want here</p>



<a name="165643883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643883">(May 14 2019 at 17:41)</a>:</h4>
<p>you can simulate this effect as follows: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=bb17a99761dc14aecb6aed29ff62c5bc" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=bb17a99761dc14aecb6aed29ff62c5bc">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=bb17a99761dc14aecb6aed29ff62c5bc</a></p>



<a name="165643907"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643907" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643907">(May 14 2019 at 17:41)</a>:</h4>
<p>(where the <code>let _val = &amp;mut st;</code> emulates the borrow that would happen for the drop)</p>



<a name="165643941"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165643941" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165643941">(May 14 2019 at 17:42)</a>:</h4>
<p>Right, so today if we <code>drop</code> a local and the drop panics, then along the cleanup path (where we continue dropping all other locals in scope) we never generate <code>StorageDead</code> for any local on that path</p>



<a name="165644006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165644006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165644006">(May 14 2019 at 17:42)</a>:</h4>
<p>and then we <code>resume</code> (the unwinding)</p>



<a name="165644050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165644050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165644050">(May 14 2019 at 17:43)</a>:</h4>
<blockquote>
<p>Right, so today if we <code>drop</code> a local and the drop panics, then along the cleanup path (where we continue dropping all other locals in scope) we never generate <code>StorageDead</code> for any local on that path</p>
</blockquote>
<p>also doesn't the panic hook get called before we even get to the cleanup path?</p>



<a name="165644073"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165644073" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165644073">(May 14 2019 at 17:43)</a>:</h4>
<p>not sure what the evaluation order is here</p>



<a name="165644173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165644173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165644173">(May 14 2019 at 17:44)</a>:</h4>
<p>hm, I would think so, yes</p>



<a name="165644200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165644200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165644200">(May 14 2019 at 17:44)</a>:</h4>
<p>in that case a <code>StorageDead</code> on the cleanup path would be too late anyway</p>



<a name="165644377"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165644377" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165644377">(May 14 2019 at 17:46)</a>:</h4>
<p>Right. On second thought, for my use case, I only care about StorageDead for locations reachable <em>within the function</em></p>



<a name="165644599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165644599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165644599">(May 14 2019 at 17:48)</a>:</h4>
<p>Right now, my analysis pass thinks that all these locals are still <code>StorageLive</code> along the cleanup path</p>



<a name="165644740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165644740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165644740">(May 14 2019 at 17:50)</a>:</h4>
<p>even for locals in disjoint scopes in the source code</p>



<a name="165644809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165644809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165644809">(May 14 2019 at 17:50)</a>:</h4>
<p>(this affects whether we can safely overlap them in the generator layout)</p>



<a name="165644893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165644893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165644893">(May 14 2019 at 17:51)</a>:</h4>
<p>So, for the purposes of my analysis, I <em>think</em> it should be valid to assume that once <code>drop</code> returns (along the return edge or the unwind edge), the local that was dropped is now <code>StorageDead</code></p>



<a name="165644959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165644959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165644959">(May 14 2019 at 17:52)</a>:</h4>
<p>This actually doesn't preclude inspecting the local from within the panic hook</p>



<a name="165645003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165645003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165645003">(May 14 2019 at 17:52)</a>:</h4>
<p>(so, sorry for posing the wrong question :) )</p>



<a name="165645122"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165645122" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165645122">(May 14 2019 at 17:54)</a>:</h4>
<p>Equivalently (from my perspective), we can generate the <code>StorageDead</code> statements to reflect this</p>



<a name="165645186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165645186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165645186">(May 14 2019 at 17:54)</a>:</h4>
<p>It sounds like doing this would be better from miri's perspective</p>



<a name="165645196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165645196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165645196">(May 14 2019 at 17:54)</a>:</h4>
<p>But might impact performance :(</p>



<a name="165645227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165645227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165645227">(May 14 2019 at 17:54)</a>:</h4>
<p>Is this making sense <span class="user-mention" data-user-id="127859">@Taylor Cramer</span> <span class="user-mention" data-user-id="120791">@RalfJ</span> ?</p>



<a name="165645292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165645292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165645292">(May 14 2019 at 17:56)</a>:</h4>
<p>Yes, that sounds right to me.</p>



<a name="165650409"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165650409" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165650409">(May 14 2019 at 18:52)</a>:</h4>
<blockquote>
<p>So, for the purposes of my analysis, I <em>think</em> it should be valid to assume that once <code>drop</code> returns (along the return edge or the unwind edge), the local that was dropped is now <code>StorageDead</code></p>
</blockquote>
<p>do you mean "sufficient to assume"?</p>



<a name="165650631"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165650631" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165650631">(May 14 2019 at 18:55)</a>:</h4>
<p>so, let me try to paraphrase: you think that it makes sense for our surface language spec to basically say that right after the <code>drop</code> comes back (on both the return and the unwind edge), there is a <code>StorageDead</code>. And that in turn you say is sufficient for your analysis to be as precise as you want it to be. You are fine with the storage hook inspecting stuff, which is actually allowed as that happens before the unwind edge is taken, i.e. before the <code>StorageDead</code> happens (ignoring Stacked Borrows concerns here). However, you are worried that actually materializing these <code>StorageDead</code> has a negative performance impact.<br>
Is that accurate?</p>



<a name="165650821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165650821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165650821">(May 14 2019 at 18:57)</a>:</h4>
<p>I agree that it seems reasonable to say that we have a <code>StorageDead</code> for locals that just got dropped. I don't know your analysis so I cannot say what this entails for you, but I view <code>StorageDead</code> as basically acting like <code>free</code> would for the heap -- after that, there's no way to ever access the memory that used to back this local again (and if <code>StorageLive</code> happens later, that's a new location, the old pointers remain dangling).<br>
What is the performance impact you are worried about?</p>



<a name="165660232"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165660232" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165660232">(May 14 2019 at 20:42)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> yes, that sounds accurate</p>



<a name="165660336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165660336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165660336">(May 14 2019 at 20:43)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> materializing <code>StorageDead</code> after both edges of a <code>drop</code> sometimes means we need to keep around more basic blocks, in addition to more statements</p>



<a name="165660563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165660563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165660563">(May 14 2019 at 20:46)</a>:</h4>
<p>I haven't run the profiler with that change specifically, but when I made a change to add <code>StorageDead</code> for <em>non-<code>Drop</code></em> locals along paths where they used to be elided, the <a href="https://perf.rust-lang.org/compare.html?start=004c549a73122a9867de4f64ac727deb95d426a5&amp;end=faed5e266ce824ddee6fff7bd061d96f7795efbc" target="_blank" title="https://perf.rust-lang.org/compare.html?start=004c549a73122a9867de4f64ac727deb95d426a5&amp;end=faed5e266ce824ddee6fff7bd061d96f7795efbc">performance hit</a> was pretty bad</p>



<a name="165660591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165660591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165660591">(May 14 2019 at 20:46)</a>:</h4>
<p>(so we had to do it for generators only, to enable the optimization without sacrificing performance)</p>



<a name="165660623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165660623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165660623">(May 14 2019 at 20:47)</a>:</h4>
<p>anyway, I'm inferring that we'll see a similar hit if I materialize these extra <code>StorageDead</code>s, but I'm not 100% sure :)</p>



<a name="165661452"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165661452" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165661452">(May 14 2019 at 20:56)</a>:</h4>
<p>also, for those locals we had to emit <code>StorageDrop</code> because otherwise the information was just not in the MIR</p>



<a name="165661527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165661527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165661527">(May 14 2019 at 20:56)</a>:</h4>
<p>for locals which are <code>drop</code> we can infer it</p>



<a name="165661554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165661554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165661554">(May 14 2019 at 20:56)</a>:</h4>
<p>although it's quite messy conceptually to be handling these two differently</p>



<a name="165661901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165661901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165661901">(May 14 2019 at 21:00)</a>:</h4>
<p>there isn't anything too surprising about it, but it pushes the complexity down to the consumers of MIR</p>



<a name="165667305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165667305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165667305">(May 14 2019 at 22:10)</a>:</h4>
<p>If new guarantees are added, this should be summarized and raised with the lang team</p>



<a name="165668253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165668253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165668253">(May 14 2019 at 22:23)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> it's a guarantee to the compiler, not people who are writing rust</p>



<a name="165668254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165668254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165668254">(May 14 2019 at 22:23)</a>:</h4>
<p>though I'm not sure if this distinction matters</p>



<a name="165668261"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165668261" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165668261">(May 14 2019 at 22:23)</a>:</h4>
<p>Probably not</p>



<a name="165668327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165668327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165668327">(May 14 2019 at 22:24)</a>:</h4>
<p>It would be good to phrase the guarantee succinctly in some issue and say why it is needed</p>



<a name="165668338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165668338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165668338">(May 14 2019 at 22:24)</a>:</h4>
<p>and what problems it may cause</p>



<a name="165668341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165668341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165668341">(May 14 2019 at 22:24)</a>:</h4>
<p>Sure, I'll open an issue</p>



<a name="165668353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165668353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165668353">(May 14 2019 at 22:25)</a>:</h4>
<p>I don't anticipate it being controversial, but it would be good to have it written down succinctly as you say</p>



<a name="165668605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165668605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165668605">(May 14 2019 at 22:28)</a>:</h4>
<p>This is basically documenting certain assumptions that the compiler already seems to make</p>



<a name="165668771"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165668771" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165668771">(May 14 2019 at 22:31)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> The assumption is that once <code>drop</code> returns, whether it succeeds or panics, you can't access the local you tried to <code>drop</code></p>



<a name="165668843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165668843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165668843">(May 14 2019 at 22:32)</a>:</h4>
<p>..and doing so would cause UB</p>



<a name="165668860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165668860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165668860">(May 14 2019 at 22:32)</a>:</h4>
<p>Is this something the lang team actually needs to discuss?</p>



<a name="165668956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165668956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165668956">(May 14 2019 at 22:34)</a>:</h4>
<p>This only applies to the MIR drop terminator, not drops in general</p>



<a name="165669133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165669133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165669133">(May 14 2019 at 22:37)</a>:</h4>
<p><span class="user-mention" data-user-id="116466">@Zoxc</span> true, but don't most drops involve a MIR drop terminator?</p>



<a name="165670302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/drop%20unwind%20soundness/near/165670302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/drop.20unwind.20soundness.html#165670302">(May 14 2019 at 23:00)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> I cc'd lang on <a href="https://github.com/rust-lang/rust/issues/60840" target="_blank" title="https://github.com/rust-lang/rust/issues/60840">#60840</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>